package com.ysd.lis.service.eq.impl;

import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.yulichang.wrapper.MPJLambdaWrapper;
import com.ysd.common.Result;
import com.ysd.lis.entity.eq.EqMaintainStandard;
import com.ysd.lis.mapper.eq.EqMaintainStandardMapper;
import com.ysd.lis.request.CommonPageDto;
import com.ysd.lis.request.eq.EqMaintainStandardDto;
import com.ysd.lis.service.eq.EqMaintainStandardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 设备管理-设备类型 服务实现类
 * </p>
 *
 * @author prs
 * @since 2024-07-31
 */
@Service
public class EqMaintainStandardServiceImpl extends ServiceImpl<EqMaintainStandardMapper, EqMaintainStandard> implements EqMaintainStandardService {

    @Autowired
    EqMaintainStandardMapper eqMaintainStandardMapper;
    @Override
    public Result saveOrUpdateMaintainStandard(EqMaintainStandardDto dto) {
        List<EqMaintainStandard> eqMaintainStandardList = dto.getEqMaintainStandardList();
        boolean b = this.saveOrUpdateBatch(eqMaintainStandardList);
        if(b){
            return Result.succ(1, "成功", null);
        }else {
            return Result.fail(400,"失败","");
        }
    }

    @Override
    public Result findMaintainStandardList(CommonPageDto param) {
        MPJLambdaWrapper<EqMaintainStandard> queryWrapper = new MPJLambdaWrapper<>();
        queryWrapper.selectAll(EqMaintainStandard.class);
        if (StringUtils.isNotBlank(param.getSeachValue())) {
            queryWrapper.and(wrapper -> wrapper.like(EqMaintainStandard::getStandardName, param.getSeachValue()).or().like(EqMaintainStandard::getStandardCode, param.getSeachValue()));
        }
        queryWrapper.eq(EqMaintainStandard::getDelFlag, 0)
                .orderByAsc(EqMaintainStandard::getSeq);
        return Result.succ(1, "查询成功", eqMaintainStandardMapper.selectList(queryWrapper));
    }

    @Override
    public Result batchDeleteMaintainStandardList(EqMaintainStandardDto dto) {
        List<EqMaintainStandard> eqMaintainStandardList = dto.getEqMaintainStandardList();
        List<String> ids = eqMaintainStandardList.stream().map(EqMaintainStandard::getId).collect(Collectors.toList());
        boolean b = this.removeByIds(ids);
        if(b){
            return Result.succ(1, "删除成功", null);
        }else {
            return Result.fail(400,"删除失败","");
        }
    }
}
